﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using metroCIS.Library;

namespace metroCIS.ViewModel
{
    public class GradeOverViewViewModel : ViewModelBase
    {
        public ObservableCollection<GradeInSemester> GradeSummary { get; set; }

        public GradeOverViewViewModel()
        {
            GradeSummary = new ObservableCollection<GradeInSemester>();
        }

        public async Task LoadGrades()
        {
            CisManager man = CisManager.Create();
            var grades = await man.GetGrades();

            var semesterSummary = grades.GroupBy(x => x.Semester).Select(x => new GradeInSemester { Semester = x.Key, Grades = x.ToList() });
            foreach (var entry in semesterSummary)
                GradeSummary.Add(entry);
        }
    }
}
